#!/usr/bin/env python
# coding: utf-8

# import numpy as np

raw_data = []

with open('build/serial_test.log', mode ='r')as file:
    lines = file.readlines()
    counter = 0
    for line in lines:
        if line.startswith("Sequence: "):
            line = line.strip('\n')
            line = int(line.strip("Sequence: "))
            raw_data.append(line)
            counter += 1
            # print(f"seq: {line}")
    print(f'total: {len(raw_data)}')

def check_continuous_increasing_with_wrap(sequence):
    MAX_UINT16 = 65535
    
    if len(sequence) < 2:
        print("序列是连续递增的")
        return
    
    for i in range(1, len(sequence)):
        if sequence[i] == 0 and sequence[i - 1] == MAX_UINT16:
            continue
        elif sequence[i] != (sequence[i - 1] + 1) % (MAX_UINT16 + 1):
            print(f"序列不是连续递增的，在位置 {i-1} 和 {i} 处中断: {sequence[i-1]} -> {sequence[i]}")
            return
    
    print("序列是连续递增的")

# # 测试数据
# sequence1 = [65534, 65535, 0, 1, 2]
# check_continuous_increasing_with_wrap(sequence1)

# sequence2 = [1, 2, 3, 5, 6, 7, 9]
# check_continuous_increasing_with_wrap(sequence2)

check_continuous_increasing_with_wrap(raw_data)

